from subprocess import Popen, PIPE, STDOUT

_shell = 'python'

def run(run_test, target_dir):
    command = "import sys\n"
    command = command + "import " + run_test + "\n"
    command = command + "_fixture_ret = " + run_test + ".fixture(\"" + target_dir  + "\")\n"
    command = command + "_ret = " + run_test + ".run(\"" + target_dir  + "\", _fixture_ret)\n"
    command = command + "sys.exit(_ret)\n"

    exe = Popen([_shell], stdout=PIPE, stderr=STDOUT, stdin=PIPE)
    stdout, stderr = exe.communicate(command)
    return exe.returncode, stdout
